<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span='8'>
          <el-input placeholder="请输入内容">
            <el-button
              slot="append"
              icon="el-icon-search"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table
        :data="orderList"
        stripe
        border
      >
        <el-table-column type="index">

        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
        >
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
        >
        </el-table-column>
        <el-table-column
          prop="order_pay"
          label="是否付款"
        >
          <template slot-scope="s">
            <!-- <pre>{{s.row}}</pre> -->
            <el-tag
              type="success"
              v-if="s.row.order_pay==='1'"
            >已付款</el-tag>
            <el-tag
              type="danger"
              v-else
            >未付款</el-tag>
          </template>
          <!-- <el-tag type="danger">标签五</el-tag> -->
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货"
        >
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="下单时间"
        >
          <template slot-scope="s">
            {{s.row.create_time|dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="openEdit"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              @click="openProgress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 编辑对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="editDialogVisible"
      @closed='editDialogClosed'
    >
      <el-form
        :rules="editFormRules"
        ref="editFormRef"
        :model="editForm"
      >
        <el-form-item
          label="请填写省市"
          prop="probablyAddress"
        >
          <el-cascader
            v-model="editForm.probablyAddress"
            :options="cityData"
            :props='cascaderProps'
            @change="cascaderChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item
          label="请填写具体地址"
          prop="detailedAddress"
        >
          <el-input
            v-model="editForm.detailedAddress"
            style='width:80%'
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="editDialogVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>

    <!-- 进度条对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="progressDialogVisible"
    >
      <span slot="footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="editDialogVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      cityData,
      editForm: {
        probablyAddress: '',
        detailedAddress: '',
      },
      editFormRules: {
        probablyAddress: [
          { required: true, message: '请输入省市', trigger: 'blur' },
        ],
        detailedAddress: [
          { required: true, message: '请输入具体地址', trigger: 'blur' },
        ],
      },
      queryInfo: {
        pagenum: 1,
        pagesize: 10,
      },
      orderList: [],
      total: 0,
      editDialogVisible: false,
      cascaderProps: {
        expandTrigger: 'hover',
      },
      progressDialogVisible: false,
    }
  },
  methods: {
    async getOrders() {
      let { data: res } = await this.$axios.get('orders', {
        params: this.queryInfo,
      })
      // console.log(res);
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
     getProgress() {
      // let { data: res } = await this.$axios.get('/kuaidi/1106975712662')
      this.$axios.get('/kuaidi/804909574412544580').then(info=>console.log(info)).catch(err=>console.log(err))
      // console.log(res)
    },
    // 分页
    handleSizeChange(newsize) {
      // console.log(newsize);
      this.queryInfo.pagesize = newsize
      this.getOrders()
    },
    handleCurrentChange(newpage) {
      // console.log(newpage);
      this.queryInfo.pagenum = newpage
      this.getOrders()
    },
    openEdit() {
      this.editDialogVisible = true
    },
    openProgress() {
      this.getProgress()
      this.progressDialogVisible = true
    },
    editDialogClosed() {
      // console.log(this.$refs.editFormRef);
      // return
      this.$refs.editFormRef.resetFields()
    },
    // 级联选择器
    cascaderChange() {
      console.log(this.editForm)
    },
  },
  created() {
    this.getOrders()
  },
}
</script>
<style lang="less" scoped>
.el-cascader {
  width: 80%;
}
</style>
